﻿using System.IO;
using Microsoft.Extensions.Configuration;

namespace SmartCity.Shared
{
    /// <summary>
    /// 配置帮助类
    /// </summary>
    public class ConfigHelper
    {
        /// <summary>
        /// 生成配置
        /// </summary>
        /// <param name="fileNames"></param>
        public static IConfigurationRoot BuildConfiguration(
            params string[] fileNames)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false);
            if (fileNames != null && fileNames.Length > 0)
            {
                foreach (var fileName in fileNames)
                {
                    builder.AddJsonFile(fileName, optional: false);
                }
            }
            return builder.Build();
        }
    }
}